package lesson04;

import java.util.Scanner;

public class Demo_402 {

    static volatile int num=0;

    public static void main(String[] args) {
        Thread thread1 =new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始");
            while (num==0){

            }
            System.out.println(Thread.currentThread().getName()+"结束");
        },"t1");
        Thread thread2 =new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            System.out.println("请输入以停止线程t1");

            num=scanner.nextInt();

        },"t2");
        thread1.start();
        thread2.start();
    }
}
